<?php 
class ContentController extends Controller{
	public $db;

	public function __init(){
		$this->db=K('Content');		
	}

	public function index(){		
		$data=$this->db->getList();
		// p($data);exit;
		$this->assign($data);   //使用分页类的固定写法
		$this->display();
	}

	public function add(){
		if(IS_POST){			
			if($this->db->addContent()){				
				$this->success('添加成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			$category=K('Category')->getList();
			$this->assign('category',$category);
			$this->display();
		}
	}

	public function edit(){
		if(IS_POST){
			// p($_POST);exit;
			if($this->db->editContent()){
				$this->success('编辑成功','index');
			}else{
				$this->error($this->db->error);
			}
		}else{
			// $aid=Q('aid',0,'intval');
			// $field=$this->db->find($aid);
			$field  =$this->db->find(Q('aid',0,'intval'));
			$category=K('Category')->getList();
			$this->assign('category',$category);		
			$field['thumb']=array(
				array('path'=>$field['thumb'])
			);
			// p($field);exit;
			$this->assign('field',$field);			
			$this->display();
		}
	}

	public function delete(){
		$aid=Q('aid',0,'intval');
		if($this->db->deleteContent($aid)){
			$this->success('删除成功','index');			
		}else{
			$this->error($this->db->error);
		}
	}



}


?>